package com.dehui.traders.ui.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.dehui.traders.R;

public class ZhoukPopView extends PopupWindow{

    private final View contentView;
    private Activity context;
    private OnKZhouClick onKZhouClick;

    public void setOnKZhouClick(OnKZhouClick onKZhouClick) {
        this.onKZhouClick = onKZhouClick;
    }

    public ZhoukPopView(Activity context){
        this.context = context;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        contentView = inflater.inflate(R.layout.popup_zhou_k, null);
        this.setContentView(contentView);
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        this.setWidth(width / 5);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
        this.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
            }
        });
        initView();
    }

    private void initView() {
        contentView.findViewById(R.id.tv_zhouk).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onKZhouClick != null)
                    onKZhouClick.onzhouClick(0);
                ZhoukPopView.this.dismiss();
            }
        });
        contentView.findViewById(R.id.tv_yuek).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onKZhouClick != null)
                    onKZhouClick.onzhouClick(1);
                ZhoukPopView.this.dismiss();
            }
        });
    }

    public void show(View view){
        this.showAsDropDown(view);
    }

    public interface OnKZhouClick{
        void onzhouClick(int i);
    }

}
